package com.ruoyi.sycs.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.hutool.core.lang.tree.Tree;
import com.ruoyi.base.domain.SyType;
import com.ruoyi.base.domain.bo.SyTypeBo;
import com.ruoyi.base.domain.vo.SyTypeVo;
import com.ruoyi.sycs.domain.BsJudgeBase;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sycs.domain.vo.BsJudgeBaseVo;
import com.ruoyi.sycs.domain.bo.BsJudgeBaseBo;
import com.ruoyi.sycs.service.IBsJudgeBaseService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 判定依据主
 *
 * @author zyb
 * @date 2024-04-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sycs/bsJudgeBase")
public class BsJudgeBaseController extends BaseController {

    private final IBsJudgeBaseService iBsJudgeBaseService;

    /**
     * 查询判定依据主列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<BsJudgeBaseVo> list(BsJudgeBaseBo bo, PageQuery pageQuery) {
        return iBsJudgeBaseService.queryPageList(bo, pageQuery);
    }

    /**
     * 根据试验类别获取明细分页
     */
    @SaCheckLogin
    @GetMapping("/pageBySyType")
    public TableDataInfo<BsJudgeBase> pageBySyType(BsJudgeBaseBo bo, PageQuery pageQuery) {
        return TableDataInfo.build(iBsJudgeBaseService.pageBySyType(bo, pageQuery));
    }

    /**
     * 导出判定依据主列表
     */
    @SaCheckLogin
    @Log(title = "判定依据主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BsJudgeBaseBo bo, HttpServletResponse response) {
        List<BsJudgeBaseVo> list = iBsJudgeBaseService.queryList(bo);
        ExcelUtil.exportExcel(list, "判定依据主", BsJudgeBaseVo.class, response);
    }

    /**
     * 获取判定依据主详细信息
     *
     * @param judgeId 主键
     */
    @SaCheckLogin
    @GetMapping("/{judgeId}")
    public R<BsJudgeBaseVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long judgeId) {
        return R.ok(iBsJudgeBaseService.queryById(judgeId));
    }

    /**
     * 新增判定依据主
     */
    @SaCheckLogin
    @Log(title = "判定依据主", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BsJudgeBaseBo bo) {
        return toAjax(iBsJudgeBaseService.insertByBo(bo));
    }

    /**
     * 修改判定依据主
     */
    @SaCheckLogin
    @Log(title = "判定依据主", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BsJudgeBaseBo bo) {
        return toAjax(iBsJudgeBaseService.updateByBo(bo));
    }

    /**
     * 删除判定依据主
     *
     * @param judgeIds 主键串
     */
    @SaCheckLogin
    @Log(title = "判定依据主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{judgeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] judgeIds) {
        return toAjax(iBsJudgeBaseService.deleteWithValidByIds(Arrays.asList(judgeIds), true));
    }

    /**
     * 获取技术指标 树列表
     */
    @SaCheckLogin
    @GetMapping("/bsJudgeBaseTree")
    public R<List<Tree<Long>>> bsJudgeBaseTree(SyType type) {
        return R.ok(iBsJudgeBaseService.bsJudgeBaseTree(type));
    }

    /**
     * 获取技术指标 树列表 根据试验类型
     */
    @SaCheckLogin
    @GetMapping("/bsJudgeBaseTreeBySyType")
    public R<List<Tree<Long>>> bsJudgeBaseTreeBySyType(SyTypeBo type) {
        return R.ok(iBsJudgeBaseService.bsJudgeBaseTreeBySyType(type));
    }


    /**
     * 根据试验id获取报告列表
     */
    @SaCheckLogin
    @GetMapping("/page")
    public TableDataInfo<SyTypeVo> page(SyTypeBo bo, PageQuery pageQuery) {
        return iBsJudgeBaseService.page(bo, pageQuery);
    }
}
